Relational Operators in C

What are Relational Operators?

A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if false, it returns 0. Relational operators are often used in decision-making and loops.

Example Code

#include < stdio.h>

int main() {
   int a = 10, b = 4;

   if (a > b)
       printf("a is greater than b\\n");
   else
       printf("a is less than or equal to b\\n");

   if (a >= b)
       printf("a is greater than or equal to b\\n");
   else
       printf("a is lesser than b\\n");

   if (a < b)
       printf("a is less than b\\n");
   else
       printf("a is greater than or equal to b\\n");

   if (a <= b)
       printf("a is lesser than or equal to b\\n");
   else
       printf("a is greater than b\\n");

   if (a == b)
       printf("a is equal to b\\n");
   else
       printf("a and b are not equal\\n");

   if (a != b)
       printf("a is not equal to b\\n");
   else
       printf("a is equal to b\\n");

   return 0;
}
            

Output

a is greater than b
a is greater than or equal to b
a is greater than or equal to b
a is greater than b
a and b are not equal
a is not equal to b